package test.vo
{
	import _Pan3D.display3D.Display3DMovie;
	import _Pan3D.display3D.interfaces.IDisplay3DMovie;
	
	import _me.Scene_data;
	
	import flash.display.Stage;
	import flash.display3D.Context3D;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	
	public class PersonSprite extends Display3DMovie implements IDisplay3DMovie
	{
		private var _stage:Stage;
		private var _isFrist : Boolean = true;
		private var _keyobj : Object = new Object;

		public function PersonSprite(context:Context3D)
		{
			super(context);
		}
		public function initStage(_tempstage:Stage):void
		{
			_stage=_tempstage;
			_stage.addEventListener(KeyboardEvent.KEY_DOWN,keydownHandler)
			_stage.addEventListener(KeyboardEvent.KEY_UP,keyupHandler)
			_stage.addEventListener(Event.ENTER_FRAME,enterFrame)
			//this._visible=false;
		}
		
		protected function enterFrame(event:Event):void
		{
			
			
			 var focus3D:PersonSprite=this;
			if (isDown(37) || isDown(65)) {
				focus3D.rotationY -= 3;
			}
			if (isDown(39) || isDown(68)) {
				focus3D.rotationY += 3;
			}
			var seepNum:Number=0.8;
			var r1 : Number = -(focus3D.rotationY+90)
			if (isDown(38) || isDown(87)) {
				r1=r1 + 180
				focus3D.x = focus3D.x + seepNum * Math.cos(r1 * Math.PI / 180);
				focus3D.z = focus3D.z+ seepNum * Math.sin(r1 * Math.PI / 180);
			}
			if (isDown(40) || isDown(83)) {
				
				focus3D.x = focus3D.x + seepNum * Math.cos(r1 * Math.PI / 180);
				focus3D.z= focus3D.z + seepNum * Math.sin(r1 * Math.PI / 180);
			}
			 Scene_data.focus3D.x=focus3D.x;
			 Scene_data.focus3D.z=focus3D.z;
			 Scene_data.focus3D.angle_y=Scene_data.focus3D.angle_y+(-focus3D.rotationY-Scene_data.focus3D.angle_y)/5;
		}
		private function keydownHandler(evt : KeyboardEvent) : void {
			_keyobj[evt.keyCode] = true;
			_isFrist = false;

		}
		
		private function keyupHandler(evt : KeyboardEvent) : void {
			delete _keyobj[evt.keyCode];

		}
		public function isDown(key : Number) : Boolean {
			return _keyobj[key] ? true : false;
		}
		
		protected function _keyDown(event:KeyboardEvent):void
		{
			trace(this.x,this.y,this.z);
			this.x++
			
		}
	}
}